/**
 * 1、Proxy
       Proxy 对象用于创建一个对象的代理，从而实现基本操作的拦截和自定义（如属性查找、赋值、枚举、函数调用等）。
    const p = new Proxy(target, handler)
术语
 * 方法
    handler.apply()
    handler.construct()
    handler.defineProperty()
    handler.deleteProperty()
    handler.get()
    handler.getOwnPropertyDescriptor()
    handler.getPrototypeOf()
    handler.has()
    handler.isExtensible()
    handler.ownKeys()
    handler.preventExtensions()
    handler.set()
    handler.setPrototypeOf()
 */
const target = {
    name: "小费",
    age: 23,
    address: []
}
//const target = []
const proxy = new Proxy(target, {
    set: function (target, propKey, value, receiver) {
        console.log(`target:${target},propKey:${propKey},value:${value},receiver:${receiver}`)
        return Reflect.set(target, propKey, value);
    },
    get: function (target, propKey) {
        console.log(`target:${target},property:${propKey},receiver:receiver`)
        for (const targetKey in target) {
            console.log(`targetKey:${targetKey} === target[${targetKey}]:${target[targetKey]}`)
        }
        return Reflect.get(target, propKey)
    },
})

console.log("proxy:", proxy)
const address = proxy.address
console.log("address:", address)
proxy.address.push({ id: 0, label: "甘肃省白银市靖远县五合乡二道渠村" })
console.log("target:", target)